﻿<script type="text/javascript">
    var toolbar_yonghu = [{
        text: '新增用户',
        iconCls: 'icon-add',
        handler: function() {
            $("#info-dengluming").textbox('setValue', '');
            $("#info-denglumima").textbox('setValue', '');
            $("#info-denglumima").textbox({ readonly: false });
            $("#info-mimaqueren").textbox('setValue', '');
            $("#info-mimaqueren").textbox({ readonly: false });
            $("#info-yonghuxingming").textbox('setValue', '');
            $('#info-yonghujuese').combobox('setValue', '');
            $("#yongHuID").val('');
            $("#yonghu-edit").dialog("open");
        }
    }, '-', {
        text: '修改用户',
        iconCls: 'icon-edit',
        handler: function() {
            var curRow = $("#xinxi_yonghu").datagrid('getSelected');
            if (curRow) {
                $("#info-dengluming").textbox('setValue', curRow.yonghudengluming);
                $("#info-denglumima").textbox('setValue', curRow.yonghumima);
                $("#info-denglumima").textbox({ readonly: true });
                $("#info-mimaqueren").textbox('setValue', curRow.yonghumima);
                $("#info-mimaqueren").textbox({ readonly: true });
                $("#info-yonghuxingming").textbox('setValue', curRow.yonghuxingming);
                $('#info-yonghujuese').combobox('setValue', curRow.yonghujuese);
                $("#yongHuID").val(curRow.id);
                $("#yonghu-edit").dialog('open');
            }
            else {
                alert("请选择要修改的用户信息。");
            }
        }
    }, '-', {
        text: '删除用户',
        iconCls: 'icon-remove',
        handler: function() {
            $("#yonghu-dlg").dialog('open');
        }
}];

        function DelYongHu() {
            var curRow = $("#xinxi_yonghu").datagrid('getSelected');
            if (curRow) {
                $.post('handler/xinxi_yonghu.ashx', { yongHuType: "3", yongHuID: curRow.id,uid:window.uid,kid:window.kid }, function(data, status) {
                    if (data == "OK") {
                        $("#yonghu-dlg").dialog('close');
                        $("#xinxi_yonghu").datagrid('load');
                        return;
                    }
                    if (data == "Failed") {
                        alert("删除用户信息失败，请重试");
                        $("#yonghu-dlg").dialog('close');
                        return;
                    }
                    alert(data);
                    $("#yonghu-dlg").dialog('close');
                });

            }
            else {
                alert("请选择要删除的用户信息。");
            }

        }

        function submitYongHuForm() {
            var dengluming = $("#info-dengluming").textbox('getText');
            var denglumima = $("#info-denglumima").textbox('getText');
            var mimaqueren = $("#info-mimaqueren").textbox('getText');
            var yonghuxingming = $("#info-yonghuxingming").textbox('getText');
            var yonghujuese = $('#info-yonghujuese').combobox('getText');
            var yonghuid = $("#yongHuID").val();
            if (dengluming && denglumima && mimaqueren && yonghuxingming && yonghujuese) {
                if (denglumima != mimaqueren) {
                    alert("密码与密码确认不一致，请检查。");
                    return false;
                }
                $.post("handler/xinxi_yonghu.ashx", { uid: window.uid, kid: window.kid, yongHuType:'2',dengluming:dengluming,denglumima:denglumima,yonghuxingming:yonghuxingming,yonghujuese:yonghujuese,yongHuID:yonghuid}, function (data, status) {
                    if (data == "OK") {
                        $("#yonghu-edit").dialog('close');
                        $("#xinxi_yonghu").datagrid('load');
                        return;
                    }
                    if (data == "Failed") {
                        alert("保存用户信息失败，请重试");
                        return;
                    }
                    alert(data);
                });
            }
            else {
                alert("信息不完整，请检查重试。");
            }

        }
        function clearYongHuForm() {
            $("#yonghu-edit").dialog('close');
        }
        $.parser.onComplete = function () {
            $("#xinxi_yonghu").datagrid({
                url: 'handler/xinxi_yonghu.ashx',
                method: 'post',
                queryParams: { yongHuType: '1',uid:window.uid,kid:window.kid }
            });
        
            $("#info-yonghujuese").combobox({
                url: 'handler/xinxi_juese.ashx',
                method: 'post',
                queryParams: { jueSeType: '1',uid:window.uid,kid:window.kid }
            });
        };
</script>

<table style="width:100%" id="xinxi_yonghu" class="easyui-datagrid" title="用户管理" data-options="border:false,singleSelect:true,collapsible:false,striped:true,toolbar:toolbar_yonghu">
    <thead>
        <tr>
            <th data-options="field:'yonghudengluming',width:150">
                登录名
            </th>
            <th data-options="field:'yonghuxingming',width:200">
                用户姓名
            </th>
            <th data-options="field:'yonghujuese',width:200">
                用户角色
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>
<div id="yonghu-edit" class="easyui-dialog" title="用户信息编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
    style="width: 500px; height: 350px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    登录名:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-dengluming" name="info-dengluming"
                        data-options="width:150"></input>
                </td>
            </tr>
            <tr>
                <td>
                    密码:
                </td>
                <td>
                    <input class="easyui-textbox" type="password" id="info-denglumima" name="info-denglumima"
                        data-options="width:150"></input>
                </td>
            </tr>
            <tr>
                <td>
                    密码确认:
                </td>
                <td>
                    <input class="easyui-textbox" type="password" id="info-mimaqueren" name="info-mimaqueren"
                        data-options="width:150"></input>
                </td>
            </tr>
            <tr>
                <td>
                    用户姓名:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-yonghuxingming" name="info-yonghuxingming"
                        data-options="width:150"></input>
                </td>
            </tr>
            <tr>
                <td>
                    用户角色:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-yonghujuese" id="info-yonghujuese" data-options="width:150, panelHeight: 'auto',editable:false, valueField: 'juesemingcheng',
                        textField: 'juesemingcheng'">
                    </select>
                </td>
            </tr>
        </table>
        <input type="hidden" name="yongHuID" id="yongHuID" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitYongHuForm()"
                data-options="iconCls:'icon-ok'">保存</a> <a href="javascript:void(0)" class="easyui-linkbutton"
                    style="width: 75px" onclick="clearYongHuForm()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>

<div id="yonghu-dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;
    padding: 10px" data-options="
				iconCls: 'icon-help',
				buttons: '#yonghu-dlg-buttons',
				modal:true,
				closed:true
			">
    确定要删除该用户信息吗？
</div>
<div id="yonghu-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelYongHu();">确定</a> 
   <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#yonghu-dlg').dialog('close');">取消</a>
</div>

